package com.xiaofeng.subject.infra.rpc;

import com.xiaofeng.auth.api.UserFeignService;
import com.xiaofeng.auth.entity.AuthUserDTO;
import com.xiaofeng.auth.entity.Result;
import com.xiaofeng.subject.infra.entity.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: chc
 * @Date: 2024/03/01/15:14
 * @Description: UserRpc模块
 */
@Component
public class UserRpc {

    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String userName) {
        //创建一个AuthUserDTO
        AuthUserDTO authUserDTO = new AuthUserDTO();
        //设置用户名
        authUserDTO.setUserName(userName);
        //根据用户名查询用户信息，通过feign调用auth模块的接口
        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);
        UserInfo userInfo = new UserInfo();
        if (!result.getSuccess()){
            return userInfo;
        }
        //获取数据
        AuthUserDTO data = result.getData();
        //设置用户名
        userInfo.setUserName(data.getUserName());
        //设置昵称
        userInfo.setNickName(data.getNickName());
        //设置头像
        userInfo.setAvatar(data.getAvatar());
        //返回数据对象
        return userInfo;
    }
}
